#ifndef HTTPBASE_INC
#define HTTPBASE_INC

#include "wch/Runnable.h"
using namespace wch;

#include <event2/event.h>
#include <event2/buffer.h>
#include <event2/http.h>

class HttpBase
	: public Runnable
{
public:
	HttpBase(UInt16);

public:
	bool init();
	void destroy();

public:
	void run();
	virtual void processReq(std::string) {}
	virtual void processResp() {}
	void processRespImpl(std::vector<std::string>&);

public:
	static void generic_handler(struct evhttp_request *, void *);
	static void generic_timer(evutil_socket_t, short, void *);

protected:
	UInt16 _port;
	struct event_base * _base;
	struct evhttp * _server;
	struct timeval _tv;
	struct event * _timer;
};

#endif